package com.yhy.tradesystem.techdata;

import java.util.ArrayList;

import com.yhy.tradesystem.Const;
import com.yhy.tradesystem.TradeDataPak;
import com.yhy.tradesystem.buysellsignal.SimpleCrossBuySellSignal;

public class BestMAFilter extends BaseTechDataFilter {

	public static final String FILTER_NAME = "自适应移动平均线";
	public static final String PARAMETER_WINDOW_DAY = "回测周期长度";
	
	public static final String DATA_BESTMA_DAY = "自适应移动平均线周期";
	public static final String DATA_BESTMA_VALUE = "自适应移动平均指标";
	
	protected int windowDay=10;
	
	private String[] parameterKeySet = {PARAMETER_WINDOW_DAY};
	private float[] parameterValueSet = {windowDay};
	private String[] techDataKeySet = {DATA_BESTMA_DAY,DATA_BESTMA_VALUE};
	private float[] techDataValueSet = {0.0f,0.0f};
	
	String filterName = FILTER_NAME;
	TechDataBestParameterFinder finder;
	
	@Override
	public void inputData(TradeDataPak data) {
		super.inputData(data);
		finder.inputData(data);
		outputData();
	}

	@Override
	public void setParameters(String name, float value) {
		if (PARAMETER_WINDOW_DAY.equals(name)) {
			windowDay = (int) value;
			parameterValueSet[0] = value;
			filterName  = FILTER_NAME+"("+windowDay+")";
			
			finder = new TechDataBestParameterFinder(MAFilter.class.getName(), null, null, MAFilter.PARAMETER_MA_DAY,MAFilter.DATA_MA+"/"+MAFilter.DATA_MA,
					SimpleCrossBuySellSignal.class.getName(), new String[]{SimpleCrossBuySellSignal.PARAMETER_FAST_LINE,SimpleCrossBuySellSignal.PARAMETER_SLOW_LINE},new String[]{Const.CLOSE,MAFilter.DATA_MA+"/"+MAFilter.DATA_MA},
					windowDay);
		}
	}

	@Override
	public float getParameters(String name) {
		if (PARAMETER_WINDOW_DAY.equals(name)) {
			return (float)windowDay;
		}
		return -1f;
	}

	@Override
	public void resetData() {
		super.resetData();
		finder = null;
		filterName = FILTER_NAME;
	}

	@Override
	public String getName() {
		return FILTER_NAME;
	}

	@Override
	public TradeDataPak outputData() {
		
		float ret[] = finder.getCurrentBestParameters(5.0f, 35.0f, 1.0f);
		techDataValueSet[0] =ret[0];
		techDataValueSet[1] =ret[1];
		TradeDataPak.TechnicalAnalysisData techdData=new TradeDataPak.TechnicalAnalysisData(getName(), parameterKeySet,parameterValueSet,techDataKeySet,techDataValueSet);
		pak.techDataList.add(techdData);
		return super.outputData();
	}

}
